﻿
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Okarito
{
    /// <summary>
    /// The <see cref="FogBugzException"/> class represents a client/server communications error.
    /// </summary>
    [Serializable]
    public sealed class FogBugzException : Exception
    {
        public FogBugzException(int code, string message)
            : this(code, message, null)
        {
        }

        public FogBugzException(int code, string message, Exception innerException)
            : base(message, innerException)
        {
            m_code = code;
        }

        public int Code
        {
            get { return m_code; }
        }

        private FogBugzException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            m_code = info.GetInt32("Code");
        }

        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("Code", m_code);
        }

        readonly int m_code;
    }
}
